package QuanLyHoaDon;

import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

public class DanhSachHoaDon extends javax.swing.JPanel {

    private DefaultTableModel modelHoaDon = new DefaultTableModel();
    Vector vLay = new Vector();

    public DanhSachHoaDon() {

        initComponents();

        try {
            vLay = HoaDon.xemDSHoaDon();
            this.taiDanhSachHoaDon(vLay);
        } catch (SQLException ex) {
            Logger.getLogger(DanhSachHoaDon.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    //Tải data vào bảng
    public void taiDanhSachHoaDon(Vector vLay) {
        modelHoaDon.setRowCount(0);
        Vector cotHoaDon = new Vector();

        cotHoaDon.addElement("Mã hóa đơn");
        cotHoaDon.addElement("Loại hóa đơn");
        cotHoaDon.addElement("Tên khách hàng");
        cotHoaDon.addElement("Tên thuốc");
        cotHoaDon.addElement("Địa chỉ");
        cotHoaDon.addElement("Ngày tạo");
        cotHoaDon.addElement("Thời hạn");
        cotHoaDon.addElement("Thuế");
        cotHoaDon.addElement("Giá");
        cotHoaDon.addElement("Tình trạng");

        modelHoaDon.setColumnIdentifiers(cotHoaDon);

        HoaDon hd = new HoaDon();

        for (int i = 0; i < vLay.size(); i++) {
            hd = (HoaDon) vLay.get(i);

            Vector hangHoaDon = new Vector();
            hangHoaDon.addElement(hd.getMaHoaDon());
            hangHoaDon.addElement(hd.getLoaiHoaDon());
            hangHoaDon.addElement(hd.getTenKhachHang());
            hangHoaDon.addElement(hd.getTenThuoc());
            hangHoaDon.addElement(hd.getDiaChi());
            hangHoaDon.addElement(hd.getNgayTao());
            hangHoaDon.addElement(hd.getThoiHan());
            hangHoaDon.addElement(hd.getThue());
            hangHoaDon.addElement(hd.getGia());
            hangHoaDon.addElement(hd.getTinhTrang());

            modelHoaDon.addRow(hangHoaDon);
        }
        tbDSHoaDon.setModel(modelHoaDon);
    }

    //Tìm kiếm hóa đơn
    public void timKiemHoaDon() throws SQLException {
        if (cbLoaiHoaDon.getSelectedItem().toString().equals("---Chọn loại hóa đơn---") && txtTenKhachHang.getText().equals("") && txtTenThuoc.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "Bạn phải chọn ít nhất một mục để tìm kiếm");
            return;
        }
        Vector vlist = new Vector();
        if (!cbLoaiHoaDon.getSelectedItem().toString().equals("---Chọn loại hóa đơn---") && txtTenKhachHang.getText().equals("") && txtTenThuoc.getText().equals("")) {
            vlist.addElement(cbLoaiHoaDon.getSelectedItem().toString().trim());
            vLay = HoaDon.timKiem("spTimKiemLoaiHoaDon", vlist);
            this.taiDanhSachHoaDon(vLay);

        } else if (cbLoaiHoaDon.getSelectedItem().toString().equals("---Chọn loại hóa đơn---") && txtTenKhachHang.getText() != "" && txtTenThuoc.getText().equals("")) {
            vlist.addElement(txtTenKhachHang.getText().trim());
            vLay = HoaDon.timKiem("spTimKiemTenKhachHang_HD", vlist);
            this.taiDanhSachHoaDon(vLay);

        } else if (cbLoaiHoaDon.getSelectedItem().toString().equals("---Chọn loại hóa đơn---") && txtTenKhachHang.getText().equals("") && !txtTenThuoc.getText().equals("")) {
            vlist.addElement(txtTenThuoc.getText().trim());
            vLay = HoaDon.timKiem("spTimKiemTenThuoc_HD", vlist);
            this.taiDanhSachHoaDon(vLay);

        } else if (!cbLoaiHoaDon.getSelectedItem().toString().equals("---Chọn loại hóa đơn---") && !txtTenKhachHang.getText().equals("") && txtTenThuoc.getText().equals("")) {
            vlist.addElement(cbLoaiHoaDon.getSelectedItem());
            vlist.addElement(txtTenKhachHang.getText());
            vLay = HoaDon.timKiem("spTimKiemLoaiHoaDon_TenKhachHang", vlist);
            this.taiDanhSachHoaDon(vLay);

        } else if (!cbLoaiHoaDon.getSelectedItem().toString().equals("---Chọn loại hóa đơn---") && txtTenKhachHang.getText().equals("") && !txtTenThuoc.getText().equals("")) {
            vlist.addElement(cbLoaiHoaDon.getSelectedItem());
            vlist.addElement(txtTenThuoc.getText());
            vLay = HoaDon.timKiem("spTimKiemLoaiHoaDon_TenThuoc", vlist);
            this.taiDanhSachHoaDon(vLay);

        } else {

            vlist.addElement(cbLoaiHoaDon.getSelectedItem());
            vlist.addElement(txtTenKhachHang.getText());
            vlist.addElement(txtTenThuoc.getText());
            vLay = HoaDon.timKiem("spTimKiemLoaiHoaDon_TenKhachHang_TenThuoc", vlist);
            this.taiDanhSachHoaDon(vLay);

        }
    }

    //Xóa Hóa đơn
    public void xoaHoaDon() {
        int r = tbDSHoaDon.getSelectedRow();
        if (r < 0) {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn mục để xóa", "Thông báo", JOptionPane.ERROR_MESSAGE);
            return;
        }
        int show = JOptionPane.showConfirmDialog(this, "Bạn có đồng ý xóa dữ liệu hóa đơn?", "Thông báo", JOptionPane.YES_NO_OPTION);
        if (show == JOptionPane.YES_OPTION) {
            int kt = 0, dem = 0;
            int[] rArr = tbDSHoaDon.getSelectedRows();
            try {
                for (int i = 0; i < rArr.length; i++) {
                    int maHoaDon = Integer.parseInt(tbDSHoaDon.getValueAt(rArr[i], 0).toString());
                    kt = HoaDon.xoaHoaDon(maHoaDon);
                    if (kt != 0) {
                        dem++;
                    }
                }

                if (dem > 0) {
                    JOptionPane.showMessageDialog(this, "Xóa " + dem + "Hóa đơn thành công", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
                    vLay = HoaDon.xemDSHoaDon();
                    this.taiDanhSachHoaDon(vLay);
                } else {
                    JOptionPane.showMessageDialog(this, "Không xóa được!", "Thông báo", JOptionPane.ERROR_MESSAGE);
                }
            } catch (SQLException ex) {
                System.err.println(ex.getMessage());
            }
        }
    }

    //Tính tổng tiền
    public void tinhTongTien() {
        try {
           
            String thamSo = txtTinhTienKhachHang.getText();
            Vector tt = new Vector();
            tt.addElement(thamSo);
            vLay = HoaDon.tinhTien("spTongTien", tt);
            HoaDon tien = new HoaDon();
            for (int i = 0; i < vLay.size(); i++) {
                tien = (HoaDon) vLay.get(i);
                String t = Float.toString(tien.getTien());
                jlTongTienMua.setText(t+"/Đồng");
            }  
        } catch (SQLException ex) {
            Logger.getLogger(DanhSachHoaDon.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
      //Tính tiền đã trả
    public void tinhTienDaTra() {
        try {
           
            String thamSo = txtTinhTienKhachHang.getText();
            Vector tt = new Vector();
            tt.addElement(thamSo);
            vLay = HoaDon.tinhTien("spTinhTien_DaTra", tt);
            HoaDon tien = new HoaDon();
            for (int i = 0; i < vLay.size(); i++) {
                tien = (HoaDon) vLay.get(i);
                String t = Float.toString(tien.getTien());
                jlTienDaTra.setText(t+"/Đồng");
            }  
        } catch (SQLException ex) {
            Logger.getLogger(DanhSachHoaDon.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
      //Tính tổng tiền
    public void tinhTienConThieu() {
        try {
           
            String thamSo = txtTinhTienKhachHang.getText();
            Vector tt = new Vector();
            tt.addElement(thamSo);
            vLay = HoaDon.tinhTien("spTinhTien_No", tt);
            HoaDon tien = new HoaDon();
            for (int i = 0; i < vLay.size(); i++) {
                tien = (HoaDon) vLay.get(i);
                String t = Float.toString(tien.getTien());
                jlTienChuaTra.setText(t+"/Đồng");
            }  
        } catch (SQLException ex) {
            Logger.getLogger(DanhSachHoaDon.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbDSHoaDon = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtTinhTienKhachHang = new javax.swing.JTextField();
        jlTongTienMua = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jlTienDaTra = new javax.swing.JLabel();
        jlTienChuaTra = new javax.swing.JLabel();
        btTinhTien = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        cbLoaiHoaDon = new javax.swing.JComboBox();
        txtTenKhachHang = new javax.swing.JTextField();
        txtTenThuoc = new javax.swing.JTextField();
        btTimKiem = new javax.swing.JButton();
        btThem = new javax.swing.JButton();
        btXoa = new javax.swing.JButton();
        btTroLai = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Danh Sách Hóa Đơn"));

        tbDSHoaDon.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tbDSHoaDon);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 603, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 194, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(21, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Tính tiền"));

        jLabel4.setText("Tên khách hàng :");

        jLabel5.setText("Tiền đã trả :");

        jLabel6.setText("Tổng tiền mua :");

        jLabel7.setText("Tiền còn thiếu :");

        btTinhTien.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/Calendar.png"))); // NOI18N
        btTinhTien.setText("Tính tiền");
        btTinhTien.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btTinhTienActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(txtTinhTienKhachHang, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(btTinhTien, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addComponent(jlTienChuaTra, javax.swing.GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE)
                            .addComponent(jlTienDaTra, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jlTongTienMua, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(txtTinhTienKhachHang))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jlTongTienMua, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(23, 23, 23)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jlTienDaTra, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(32, 32, 32)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jlTienChuaTra, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(btTinhTien)
                .addGap(21, 21, 21))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Tìm kiếm"));

        jLabel1.setText("Tên khách hàng :");

        jLabel2.setText("Loại hóa đơn :");

        jLabel3.setText("Tên thuốc :");

        cbLoaiHoaDon.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---Chọn loại hóa đơn---", "Xuất hàng", "Nhập hàng" }));

        txtTenKhachHang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtTenKhachHangActionPerformed(evt);
            }
        });

        btTimKiem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/Search.png"))); // NOI18N
        btTimKiem.setText("Tìm kiếm");
        btTimKiem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btTimKiemActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(56, 56, 56)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(cbLoaiHoaDon, 0, 182, Short.MAX_VALUE)
                    .addComponent(txtTenKhachHang)
                    .addComponent(txtTenThuoc))
                .addGap(0, 46, Short.MAX_VALUE))
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(94, 94, 94)
                .addComponent(btTimKiem, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cbLoaiHoaDon, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(28, 28, 28))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(txtTenKhachHang, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)))
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtTenThuoc, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btTimKiem)
                .addGap(6, 6, 6))
        );

        btThem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/add 1.png"))); // NOI18N
        btThem.setText("Thêm");
        btThem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btThemActionPerformed(evt);
            }
        });

        btXoa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/Delete.png"))); // NOI18N
        btXoa.setText("Xóa");
        btXoa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btXoaActionPerformed(evt);
            }
        });

        btTroLai.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/Go-back.png"))); // NOI18N
        btTroLai.setText("Trở Lại");
        btTroLai.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btTroLaiActionPerformed(evt);
            }
        });

        jLabel8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/123.png"))); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(btThem, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(btXoa, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(88, 88, 88)
                                .addComponent(btTroLai)
                                .addGap(0, 0, Short.MAX_VALUE))))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addGap(109, 109, 109)
                        .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel8)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(btThem)
                                    .addComponent(btXoa))
                                .addGap(27, 27, 27)
                                .addComponent(btTroLai)))))
                .addGap(0, 20, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btThemActionPerformed
        // TODO add your handling code here:
        new ThemHoaDon().setVisible(true);

    }//GEN-LAST:event_btThemActionPerformed

    private void txtTenKhachHangActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtTenKhachHangActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtTenKhachHangActionPerformed

    private void btTimKiemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btTimKiemActionPerformed
        try {
            // TODO add your handling code here:
            this.timKiemHoaDon();
        } catch (SQLException ex) {
            Logger.getLogger(DanhSachHoaDon.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btTimKiemActionPerformed

    private void btXoaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btXoaActionPerformed
        // TODO add your handling code here:
        this.xoaHoaDon();
    }//GEN-LAST:event_btXoaActionPerformed

    private void btTroLaiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btTroLaiActionPerformed
        // TODO add your handling code here:
        txtTenKhachHang.setText("");
        txtTenThuoc.setText("");
        try {
            vLay = HoaDon.xemDSHoaDon();
            this.taiDanhSachHoaDon(vLay);
        } catch (SQLException ex) {
            Logger.getLogger(DanhSachHoaDon.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btTroLaiActionPerformed

    private void btTinhTienActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btTinhTienActionPerformed
        // TODO add your handling code here:
        if(txtTinhTienKhachHang.getText().equals("")){
            JOptionPane.showMessageDialog(null, "Bạn chưa nhập tên khách hàng.");
        }else{
        this.tinhTongTien();
        this.tinhTienDaTra();
        this.tinhTienConThieu();
        }
    }//GEN-LAST:event_btTinhTienActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btThem;
    private javax.swing.JButton btTimKiem;
    private javax.swing.JButton btTinhTien;
    private javax.swing.JButton btTroLai;
    private javax.swing.JButton btXoa;
    private javax.swing.JComboBox cbLoaiHoaDon;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel jlTienChuaTra;
    private javax.swing.JLabel jlTienDaTra;
    private javax.swing.JLabel jlTongTienMua;
    private javax.swing.JTable tbDSHoaDon;
    private javax.swing.JTextField txtTenKhachHang;
    private javax.swing.JTextField txtTenThuoc;
    private javax.swing.JTextField txtTinhTienKhachHang;
    // End of variables declaration//GEN-END:variables
}
